#ifndef __VIDEO_H_
#define __VIDEO_H_

#include "def.h"
#include "porting.h"
#include "video_api.h"
#include "mem.h"
#include "demux_avi.h"

#ifdef _WIN32
#define DB
#define DBx(x)
#define DBxy(x,y)
#define TICK1
#define TICK2
#else
#define DB xprintf("%s:%d\n", __func__, __LINE__);
#define DBx(x) xprintf("%s:%d:%d\n", __func__, __LINE__, x);
#define DBxy(x,y) xprintf("%s:%d:%d,%d\n", __func__, __LINE__, x, y);
#define TICK1 {uint32_t tick = OAL_get_tick_count();
#define TICK2 xprintf("----------------------------------> time:%d\n", OAL_get_tick_count() - tick);}
#endif

typedef struct
{
	u8 fname[OAL_MAX_PATH];
	VIDEO_CB cb;
	volatile uint8_t volume;
	volatile int pause;

	FIL favi;
	OAL_QUEUE queue1;
	OAL_QUEUE queue2;
	OAL_QUEUE queue3;
	OAL_THREAD thread1;
	OAL_THREAD thread2;
}VIDEO_CONTEXT;

typedef enum
{
	MSGID_QUIT = -1,
	MSGID_SEEK = 0,
	MSGID_PAUSE = 1,
	MSGID_VOLUME = 2,
	MSGID_H264_PKG = 3,
	MSGID_H264_FRM = 4,
	MSGID_AUDIO_FRM = 5,
}VIDEO_MSGID;

typedef struct
{
	VIDEO_MSGID id;
	int wp;
	int lp;
}VIDEO_MSG;

extern VIDEO_CONTEXT* g_video_context;

VIDEO_ERROR _video_init();
VIDEO_ERROR _video_free();

VIDEO_ERROR _play_start(char* fname, VIDEO_CB cb);
VIDEO_ERROR _play_stop();
VIDEO_ERROR _play_pause();
VIDEO_ERROR _play_resume();
VIDEO_ERROR _play_seek(int offset);
VIDEO_ERROR _play_set_volume(unsigned char volume);

VIDEO_ERROR _record_start(char* fname, VIDEO_CB cb);
VIDEO_ERROR _record_stop();
VIDEO_ERROR _record_pause();
VIDEO_ERROR _record_resume();

#endif
